package cn.tedu.rabbitmq.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class RbtMQController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 测试接口send
    @GetMapping("/send")
    public String send(String msg) {
        // 将参数msg组织称消息发送到rabbitmq 等待消费者监听消费
        // convertAndSend，可以将任意消息体数据对象（只要其实现了序列化接口）发送到指定交换机
        // channel.basicPublish(exchange, routingKey, body); 交换机名称，路由键，消息序列化数组
//        rabbitTemplate.convertAndSend("demo-ex", "demo-rk", msg);
        msg = "延迟队列消息001";
        rabbitTemplate.convertAndSend("biz-ex", "biz-rk", msg);
        return "发送成功！" + new Date().toLocaleString();
    }
}
